package com.sxdb.webadmin.controller;

import com.sxdb.webadmin.bean.Student;
import com.sxdb.webadmin.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author MAXIAO
 * @create 2021-04-20-11:43
 */

@Controller
public class StudentController {


    @Autowired
    StudentService studentService;

    @ResponseBody
    @GetMapping("/student")
    public Student student(@RequestParam("id") int id) {
        Student student = studentService.getSdudentFormId(id);
        return student;
    }

    @Transactional
    @ResponseBody
    @GetMapping("/addStudent")
    public String insertStudent(@RequestParam("id") int id,
                                @RequestParam("userId") int userId,
                                @RequestParam("name") String name,
                                @RequestParam("email") String email,
                                @RequestParam("age") int age) {
        Student student = new Student();
        student.setId(id);
        student.setUserId(userId);
        student.setName(name);
        student.setEmail(email);
        student.setAge(age);
        studentService.addStudent(student);
        return "success";
    }

}
